﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using Besture.Bll;
using Besture.Dal;

using Besture.Model;
using Besture.Common;
using Besture.Model.XiangSheng;
using Besture.UI.Common;

namespace Besture.UI.Portal.Pay
{
    public partial class OrderSuccess : UserPage
    {
        //public static string Img_Path = "Resource/images/";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OrderPay_Order_Model model = (OrderPay_Order_Model)HttpContext.Current.Session["PayInfo"];
                if (model != null)
                {
                    this.lblHotelName.Text = model.HotelsName;
                    this.lblPrice.Text = model.ActuallyPaidPrice.ToString();
                }
            }
        }

        /// <summary>
        /// 查询推荐酒店列表
        /// 会员支付页面显示
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [WebMethod]
        public static string GetHotelsRecommend()
        {
            string json = "";
            int userID = 0;

            if (HttpContext.Current.Session[Constants.SESSION_WEB_USER_MODEL] != null)
            {
                UserBaseModel model = (UserBaseModel)HttpContext.Current.Session[Constants.SESSION_WEB_USER_MODEL];
                userID = model.ID;
            }

            StringBuilder sb = new StringBuilder();
            HotelsDac dac = new HotelsDac();
            DataSet ds = dac.GetHotelsRecommendPay(userID);

            IList<HotelsModel> listHotel = ModelConvertHelper<HotelsModel>.ConvertToModelList(ds.Tables[0]);
            IList<HotelList_Fav_Model> listFav = ModelConvertHelper<HotelList_Fav_Model>.ConvertToModelList(ds.Tables[1]);

            for (int i = 0; i < listHotel.Count; i++)
            {
              
                
                sb.Append("{");
                sb.Append("\"ID\":\"" + listHotel[i].ID + "\",");
                sb.Append("\"HotelsName\":\"" + listHotel[i].HotelsName + "\",");
                sb.Append("\"HotelsImage\":\"" + Constants.PATH_IMAGE_CONTENT + listHotel[i].HotelsImage + "\",");
                sb.Append("\"Address\":\"" + StringHelper.StringTruncat(listHotel[i].Address,25,"....") + "\",");
                sb.Append("\"Score\":\"" + listHotel[i].Score.ToString("f1").Replace(".0","") + "\",");
                if (listFav.Where(p => p.HotelID == listHotel[i].ID).SingleOrDefault() != null)
                {
                    sb.Append("\"IsFav\":\"fav2.png\"");
                }
                else
                {
                    sb.Append("\"IsFav\":\"fav.png\"");
                }
                sb.Append("},");

                if (listHotel.Count > 3)
                {
                    if (i == 2)
                    {
                        json += "{\"items\":[" + sb.ToString().Trim(',') + "]},";
                        sb.Clear();
                    }
                    if (i == listHotel.Count - 1)
                    {
                        json += "{\"items\":[" + sb.ToString().Trim(',') + "]}";
                    }
                }
                else
                {
                    if (i == listHotel.Count - 1)
                    {
                        json += "{\"items\":[" + sb.ToString().Trim(',') + "]},{\"items\":[]}";
                    }
                }
            }

            return "[" + json + "]";
        }
    }
}